package com.zntech.app.common.instantcmd;

import static android.view.KeyEvent.KEYCODE_APP_SWITCH;
import static android.view.KeyEvent.KEYCODE_BACK;
import static android.view.KeyEvent.KEYCODE_HOME;

import android.content.Context;
import android.graphics.Point;
import android.graphics.PointF;
import android.view.MotionEvent;

/**
 * instantcmd 触摸事件、keycode事件接口
 */
public class InstantCmd {

    /**
     * 在application中初始化
     */
    public static void init(Context context){
        InstantCmdClient.get().init(context);
    }

    public static void destroy(){
        InstantCmdClient.get().destroy();
    }

    /**
     * touch事件，当前只支持单点
     * @param event MotionEvent.ACTION_DOWN MotionEvent.ACTION_UP MotionEvent.ACTION_MOVE
     * @param x
     * @param y
     */
    public static void touch(int event, float x, float y, int delayTime) {
        InstantCmdClient.get().touch(event, x, y, delayTime);
    }
    public static void touch(int event, float x, float y){
        InstantCmdClient.get().touch(event, x, y, 0);
    }

    /**
     * 滑动模拟（匀速）
     * @param startX 开始的点x
     * @param startY 开始的点y
     * @param endX 结束的点x
     * @param endY 结束的点y
     * @param duration 时长，默认500ms
     */
    public static void slide(float startX, float startY, float endX, float endY, int duration) {
        InstantCmdClient.get().slide(startX, startY, endX, endY, duration);
    }
    public static void slide(float startX, float startY, float endX, float endY) {
        InstantCmdClient.get().slide(startX, startY, endX, endY, 500);
    }
    /**
     * 单击模拟
     * @param x  坐标点
     * @param y  坐标点
     * @param stayTime 停留时长 默认500ms
     * @return
     */
    public static void click(float x, float y, int stayTime) {
        touch(MotionEvent.ACTION_DOWN, x, y);
        // 延迟发送up事件
        touch(MotionEvent.ACTION_UP, x, y, stayTime);
    }
    public static void click(float x, float y) {
        click(x, y, 500);
    }

    public static void doKeyHome() {
        InstantCmdClient.get().doKeycode(KEYCODE_HOME, 100);
    }

    public static void doKeyRecent() {
        InstantCmdClient.get().doKeycode(KEYCODE_APP_SWITCH, 100);
    }

    public static void doKeyBack() {
        InstantCmdClient.get().doKeycode(KEYCODE_BACK, 100);
    }

    public static void doKeycode(int keycode) {
        InstantCmdClient.get().doKeycode(keycode, 100);
    }

    public static void doPaste(){
        InstantCmdClient.get().doPaste(100);
    }

    /**
     * 请求截图
     * @param filePath 文件路径
     */
    public static void doScreenshot(String filePath){
        InstantCmdClient.get().doScreenshot(filePath, 300);
    }

    /**
     * 注册touch组件
     * @param intentAction 所属服务的action
     */
    public static void registerComponent(String intentAction){
        InstantCmdClient.get().registerComponent(intentAction);
    }
}
